package org.example.sward.tooffer;

public class Offer56 {

    public static void main(String[] args) {
        Offer56 offer56 = new Offer56();
        int[] nums = {4,1,4,6};
        int[] res = offer56.singleNumbers(nums);
        for (int i : res){
            System.out.println(i);
        }
    }

    public int[] singleNumbers(int[] nums) {
        int x = 0,y = 0,n = 0, m = 1;
        //遍历异或
        for(int num : nums){
            n ^= num;
        }
        //2.循环左移，计算m
        while ((n & m) == 0){
            m <<= 1;
        }
        for(int num : nums){
            if((num & m) != 0){
                x ^= num;
            }else{
                y ^= num;
            }
        }
        return new int[]{x,y};
    }
}
